package com.zidian.study.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import com.zidian.student.trucks.R;
import com.mingming.com.library.OnInitSelectedPosition;
import com.zidian.study.utils.ToastUtil;

/**
 * Created by HanHailong on 15/10/19.
 * 标签文字适配器
 */
public class TagTextAdapter<T> extends BaseAdapter implements OnInitSelectedPosition {

    protected final Context mContext;
    protected final List<T> mDataList;
    //表情选择
    private static final int[] TAG_IMAGE_SELECTORS = {
            R.drawable.tag_image_selector_score5,
            R.drawable.tag_image_selector_score4,
            R.drawable.tag_image_selector_score3,
            R.drawable.tag_image_selector_score2,
            R.drawable.tag_image_selector_score1};


    public TagTextAdapter(Context context) {
        this.mContext = context;
        mDataList = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.item_evaluate_text_tag, parent, false);
        ImageView imageView = (ImageView) view.findViewById(R.id.tag_iv);
        imageView.setImageResource(TAG_IMAGE_SELECTORS[position]);
        TextView textView = (TextView) view.findViewById(R.id.tag_tv);
        T t = mDataList.get(position);

        if (t instanceof String) {
            textView.setText((String) t);
        }
        return view;
    }

    public void onlyAddAll(List<T> datas) {
        mDataList.addAll(datas);
        notifyDataSetChanged();
    }

    public void clearAndAddAll(List<T> datas) {
        mDataList.clear();
        onlyAddAll(datas);
    }

    private int count = 99;

    /**
     * 设置预选
     * @param position
     */
    public void setSelectedItem(int position) {
        count = position;
    }


    @Override
    public boolean isSelectedPosition(int position) {
        if (position == count) {

            return true;
        } else {
            return false;
        }
    }
}
